package org.wattdepot.cli.commands;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

/**
 * This class tests the total power command of the 
 * CommandLineInterface's actual commands.
 * 
 * @author David Mau
 */
public class TestCommandTotalPower {
  String cr = System.getProperty("line.separator");

  /**
   * Tests the normal operation of the total power command.
   */
  @Test
  public void testTotalPower() {
    // Create a new power total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_WAIAU", "2009-11-15T12:13:00.000-10:00", "LSFO" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Ready the known output.
    String knownOutput = "176.0 MegaWatts";
    knownOutput = knownOutput.concat(cr);
    
    // Compare the two to see if they are the same.
    int result = sourceOutput.compareTo(knownOutput);
    assertSame("Checking known power generated with good time stamp and fuel type", result, 0);
    
    // Create a new list to store the args for the second test
    args = Arrays.asList( "SIM_IPP", "2009-10-26T18:15:00.000-10:00", "waste");
    
    // Get the output from the command
    sourceOutput = command.doCommand( args );
    
    // Ready the known output.
    knownOutput = "46.0 MegaWatts";
    knownOutput = knownOutput.concat(cr);
    
    // Compare the two to see if they are the same.
    result = sourceOutput.compareTo(knownOutput);
    assertSame("Checking other known power generated with good time stamp and fuel type", 
        result, 0);
  }
  
  /**
   * Test bad source detection for the total power command.
   */
  @Test
  public void testTotalPowerBadSource() {
    // Create a new total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "MUSCLES", "2009-10-31T23:45:00.000-10:00", "waste" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the correct error returned
    assertTrue("Checking for correct response to bad source", sourceOutput
        .contains(WattDepotCliCommand.resourceNotFound));
  }
  
  /**
   * Test bad time stamp detection for the total power command.
   */
  @Test
  public void testTotalPowerBadTime() {
    // Create a new total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_OAHU_GRID", "BACK TO THE FUTURE", "LSFO" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the correct error returned
    assertTrue("Checking for correct response to bad timestamp", sourceOutput
        .contains(WattDepotCliCommand.badTimeStamp));
  }
  
  /**
   * Test bad fuel type detection for the total power command.
   */
  @Test
  public void testTotalPowerBadFuelType() {
    // Create a new total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_IPP", "2009-10-27T18:15:00.000-10:00", "Courage" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the correct error returned
    assertTrue("Checking for correct response to bad fuel type", 
        sourceOutput.contains(WattDepotCliCommand.fuelTypeNotFound));
  }
  
  /**
   * Tests to see if the total power command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2", "3", "4");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess total power argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the total power command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new total power command object.
    TotalPowerCommand command = new TotalPowerCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking total power handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
